package com.tcu.vod.controller;

import com.tcu.result.R;
import com.tcu.vod.entity.PlayInfo;
import com.tcu.vod.entity.VideoPlayAuth;
import com.tcu.vod.service.IVod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/vod")
public class VodController {
    private IVod vod;

    @Autowired
    public void setVod(IVod vod) {
        this.vod = vod;
    }
    @PostMapping("uploadVod")
    public R uploadVod(MultipartFile file){
        String videoId = vod.uploadVideo(file);
        return R.success().data("videoId", videoId);
    }
    @DeleteMapping("deleteVod/{videoId}")
    public R deleteVodById(@PathVariable String videoId){
        vod.deleteVideo(videoId);
        return R.success();
    }
    @GetMapping("getPlayInfo/{id}")
    public R getPlayInfo(@PathVariable String id){
        PlayInfo playInfo = vod.getPlayInfo(id);
        return R.success().data("playInfo", playInfo);
    }
    @GetMapping("getPlayAuth/{id}")
    public R getPlayAuth(@PathVariable String id){
        VideoPlayAuth videoPlayAuth = vod.getVideoPlayAuth(id);
        return R.success().data("playAuth", videoPlayAuth);
    }

}
